<!--待确认-->
<template>
  <div class="fianlJudment">
    <el-form :inline="true" :model="checkForm" label-width="100px" class="demo-ruleForm" ref="checkForm">
      <el-form-item label="办理结果" prop="approveStatus"  :rules="[{ required: true, message: '请选择办理结果', trigger: 'change' }]" label-width="150px" style="width: 100%;">
        <el-radio-group v-model="checkForm.approveStatus" @change="handleChange">
          <el-radio label="3" class="red">退件</el-radio>
          <el-radio label="5" class="red">拒件</el-radio>
          <el-radio label="9" class="red">通过</el-radio>
        </el-radio-group>
      </el-form-item>

        <el-form-item label="审批金额" prop="approvalConclusionDTO.approveAmount" v-if="checkForm.approveStatus == 9" label-width="150px"  
          :rules="[{ required: false, message: '审批金额不能为空', trigger: 'blur' }]">
          <el-input style="width: 300px;" type="number" v-model="checkForm.approvalConclusionDTO.approveAmount"><template slot="append">万</template></el-input>
        </el-form-item>
        <el-form-item label="抵押类型" prop="approvalConclusionDTO.pledgeType" v-if="checkForm.approveStatus == 9" label-width="150px" style="width: 50%;"
          :rules="[{ required: false, message: '请选择抵押类型', trigger: 'change'}]">
          <DicSelect  dictType = "抵押类型" :dictValue="checkForm.approvalConclusionDTO.pledgeType" v-on:dictValue="typeChange"/> 
        </el-form-item>
        <el-form-item label="年限" prop="approvalConclusionDTO.loanTerm" v-if="checkForm.approveStatus == 9" label-width="150px"
          :rules="[{ required: false, message: '年限不能为空', trigger: 'blur' }]">
          <el-input style="width: 300px;" type="number" v-model="checkForm.approvalConclusionDTO.loanTerm"><template slot="append">年</template></el-input>
        </el-form-item>
        <el-form-item label="资方" prop="approvalConclusionDTO.capitalSourceId" v-if="checkForm.approveStatus == 9" label-width="150px" style="width: 50%;"
          :rules="[{ required: false, message: '请选择资方', trigger: 'change' }]">
          <el-select 
              style="min-width:100%;"
              v-model="checkForm.approvalConclusionDTO.capitalSourceId" 
              @change="change"
              clearable
            >
              <el-option v-for="(item) in captialList" value-key="id" :key="item.id" :value="item.id" :label="item.capitalName"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="产品名称" prop="approvalConclusionDTO.capitalProductId" v-if="checkForm.approveStatus == 9" label-width="150px" 
          :rules="[{ required: false, message: '请选择产品', trigger: 'blur' }]">
          <!-- <el-input style="width: 300px;" disabled type="text" v-model="checkForm.approvalConclusionDTO.productName"></el-input> -->
           <el-select 
              style="min-width:100%;"
              v-model="checkForm.approvalConclusionDTO.capitalProductId" 
              @change="productChange"
              clearable
            >
              <el-option v-for="(item) in productList" value-key="id" :key="item.id" :value="item.id" :label="item.productName"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item label="利率" prop="approvalConclusionDTO.annualInterestRate" v-if="checkForm.approveStatus == 9" label-width="150px" style="width: 50%;"
          :rules="[{ required: false, message: '利率不能为空', trigger: 'blur' }]">
          <el-input style="width: 300px;" disabled type="number" v-model="checkForm.approvalConclusionDTO.annualInterestRate"><template slot="append">%</template></el-input>
        </el-form-item>
        <el-form-item label="还款方式" prop="approvalConclusionDTO.repayMethod" v-if="checkForm.approveStatus == 9" label-width="150px" style="width: 450px;"
          :rules="[{ required: false, message: '请选择还款方式', trigger: 'change' }]">
          <DicSelect  dictType = "还款方式" :dictValue="checkForm.approvalConclusionDTO.repayMethod" v-on:dictValue="checkForm.approvalConclusionDTO.repayMethod = $event"/> 
        </el-form-item>
        <el-form-item label="抵押率" prop="approvalConclusionDTO.mortgageRate" v-if="checkForm.approveStatus == 9" label-width="150px" style="width: 50%;"
          :rules="[{ required: false, message: '抵押率不能为空', trigger: 'blur' }]">
          <el-input style="width: 300px;" type="number" v-model="checkForm.approvalConclusionDTO.mortgageRate"><template slot="append">%</template></el-input>
        </el-form-item>
        <el-form-item label="带条件批复意见" prop="approvalConclusionDTO.approvalDesc" v-if="checkForm.approveStatus == 9" label-width="150px" style="width: 450px;"
          :rules="[{ required: false, message: '带条件批复意见不能为空', trigger: 'blur' }]">
          <el-input style="width: 300px;" type="textarea" v-model="checkForm.approvalConclusionDTO.approvalDesc"></el-input>
        </el-form-item>
        
        <el-form-item label="批复时间" prop="approvalConclusionDTO.replyTime" v-if="checkForm.approveStatus == 9" label-width="150px"  
          :rules="[{ required: true, message: '批复时间不能为空', trigger: 'blur' }]">
            <el-date-picker :picker-options="pickerOption" v-model="checkForm.approvalConclusionDTO.replyTime" type="datetime" placeholder="选择日期" style="width: 300px" value-format="yyyy-MM-dd HH:mm:ss"> </el-date-picker>
        </el-form-item>
      <el-form-item label="反馈信息" prop="opinion" label-width="150px"  style="width: 100%;">
        <el-input type="textarea" :rows="7" v-model="checkForm.opinion" style="width: 300px"></el-input>
      </el-form-item>

      <el-form-item  label-width="150px"  label=" ">
        <el-button type="primary" @click="submitForm('checkForm')" v-loading="loading">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { toBeComfirmed,capitalDetail,finalReview,approvalDetail } from '@/api/project';
import { uploadPath,createApprovalFile } from '@/api/projectFile'
import DicSelect from '@/components/select'
import { getToken } from '@/utils/auth'
import {quertAllCapital,quertChoose} from "@/api/dashboard"
import { mapGetters } from 'vuex';
import pdf from 'vue-pdf'
export default {
   props: {
     projectId: undefined,
     taskId: undefined,
     itemActiveIndex:undefined
  },
  components: { DicSelect,pdf },
  data() {
    return {
      pickerOption: {
        disabledDate(current) {
          return current && current.getTime() > new Date().getTime();
        },
      },
      checkForm: {
        approveStatus: undefined,
        opinion: undefined,
       approvalConclusionDTO:{
          approveAmount: undefined,
          pledgeType:undefined,
          loanTerm: undefined,
          capitalSourceId: undefined,
          capitalProductId: undefined,
          annualInterestRate: undefined,
          // productName: undefined,
          approvalType:2,
          repayMethod: undefined,
          mortgageRate: undefined,
          approvalDesc: undefined,
          replyTime:undefined
        }
      },
      captialList: [],
      productList:[],
      loading: false,
      dialogFormVisible:false,
      
      uploadPath,
      dataForm: {
        fileTypeName: undefined,
        fileNum: undefined,
        createTime: undefined,
        description:undefined,
        createName:undefined,
        picUrl: undefined
      },
      galleryFileList:[],
      previewPicUrlList:[]
    };
  },
  computed: {
    ...mapGetters(['roles']),
    headers() {
      return {
        'Authorization': "Bearer-"+getToken()
      }
    }
  },
  created() {
    this.getCaptialList();
  },
  methods: {
    submitForm(checkForm) {
      if (this.checkForm.approveStatus == undefined) {
        this.$message.error('请选择办理结果！');
        return;
      }
      this.$refs[checkForm].validate((valid) => {
          if (valid) {
            this.checkForm.projectId = this.projectId,
            this.checkForm.taskId = this.taskId,
            this.$confirm('你确定要提交吗?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning',
            }).then(() => {
              // 开始提交信息
              this.loading = true;
              finalReview(this.checkForm).then((data) => {
                this.loading = false;
               this.$notify.success({
                title: '成功',
                message: '操作成功'
              })
                this.$store.dispatch("tagsView/delView", this.$route);
                this.$router.go(-1);
              }).catch(() => {
                this.loading = false;
              })
            });
          } else {
            return false;
          }
        });
    },
    //节点判断
    handleChange(val) {
      console.log(val)
      this.restForm();
      this.checkForm.approveStatus = val;
      if(val === '9') {
        this.approvalDetail()
      }
    },
    typeChange(value) {
      this.checkForm.approvalConclusionDTO.pledgeType = value;
      if(value != ""){
        this.productChange()
      }else{
        this.$set(this.checkForm.approvalConclusionDTO,"annualInterestRate", undefined)
      }
      
    },
    restForm() {
      this.checkForm = {
        opinion: undefined,
        approveStatus: undefined,
        approvalConclusionDTO:{
          approveAmount: undefined,
          pledgeType:undefined,
          loanTerm: undefined,
          capitalSourceId: undefined,
          capitalProductId: undefined,
          annualInterestRate: undefined,
          // productName: undefined,
          approvalType:2,
          repayMethod: undefined,
          mortgageRate: undefined,
          approvalDesc: undefined
        }
      };
    },
    getCaptialList() {
       quertAllCapital()
        .then(res => {
          this.captialList = res.data
        })
        .catch(() => {
          this.captialList = []
        })
    },change(e) {
      if(this.checkForm.approvalConclusionDTO.capitalSourceId == undefined || this.checkForm.approvalConclusionDTO.capitalSourceId == "") {
        
        this.$set(this.checkForm.approvalConclusionDTO,"capitalProductId", undefined)
        this.$set(this.checkForm.approvalConclusionDTO,"annualInterestRate", undefined)
        this.productList = []
        return false
      }
      if(this.checkForm.approvalConclusionDTO.capitalSourceId != "" || this.checkForm.approvalConclusionDTO.capitalSourceId != undefined || this.checkForm.approvalConclusionDTO.capitalSourceId != "undefined") {
        
        this.$set(this.checkForm.approvalConclusionDTO,"capitalProductId", undefined)
        this.$set(this.checkForm.approvalConclusionDTO,"annualInterestRate", undefined)
        quertChoose({capitalId: this.checkForm.approvalConclusionDTO.capitalSourceId,productType:1})
        .then(res => {
          this.productList = res.data
        })
        .catch(() => {
          this.productList = []
        })
      }else{
        this.productList = []
      }
      
    },
    productChange(e) {
      if(this.checkForm.approvalConclusionDTO.capitalProductId == undefined || this.checkForm.approvalConclusionDTO.capitalProductId == "") {
        this.$set(this.checkForm.approvalConclusionDTO,"annualInterestRate", undefined)
        return false
      }
      if(this.checkForm.approvalConclusionDTO.capitalProductId != "" || this.checkForm.approvalConclusionDTO.capitalProductId != undefined || this.checkForm.approvalConclusionDTO.capitalProductId != "undefined") {
        let item = this.productList.filter(item => item.id == this.checkForm.approvalConclusionDTO.capitalProductId)
        capitalDetail({capitalId: item[0].id})
        .then(res => {
          let pledgeType = this.checkForm.approvalConclusionDTO.pledgeType;
          this.$set(this.checkForm.approvalConclusionDTO,"annualInterestRate", pledgeType == "" || pledgeType == undefined ? this.$set(this.checkForm.approvalConclusionDTO,"annualInterestRate", undefined) : pledgeType == 1 || pledgeType == 3 ? res.data.oneBetRate : res.data.twoBetRate)
           
        })
      }else{
        this.$set(this.checkForm.approvalConclusionDTO,"annualInterestRate", undefined)
      }
      
    },
    approvalDetail() {
      approvalDetail({approvalType:2,projectId:this.projectId})
        .then(res => {
          this.checkForm.approvalConclusionDTO = res.data;
          console.log(this.checkForm.approvalConclusionDTO)
        })
    }
  },
   
};
</script>

<style>
.fianlJudment .el-form-item__content{
  width:300px;
}
</style>